package com.chapter05;

import com.bdqn.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class Test03_PreparedStatement {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        long start = System.currentTimeMillis();

        Connection connection = JDBCUtils.getConnection();
        String sql = "INSERT INTO goods(`name`) VALUES(?);";
        PreparedStatement statement = connection.prepareStatement(sql);

        for (int i = 0; i < 20000; i++) {
            statement.setString(1, "zhangsan" + i);
            statement.executeUpdate();
        }

        JDBCUtils.closeResource(connection, statement, null);

        long end = System.currentTimeMillis();
        System.out.println(end - start);
        // statement: 51662ms
        // preparedstatement: 56398ms
    }
}
